import pandas as pd
import yaml
from yaml import SafeLoader

from datareport.api import ConfigClass
from datareport.api.DataSource import DataSource
from datareport.api.annotation.Font import Font
from datareport.impl.paragraph.base.BaseParagraph import BaseParagraph
from datareport.api.annotation.Style import style


@style()
class BasicInformationContent_11(BaseParagraph):
    """
    人数内容
    """

    def __init__(self):
        super().__init__()
        self.text = '''截至{}年12底，学校共有基层党支部{}个，党员{}名'''
        self.fonts=[]
        self.section = 3
        self.sort = 4

    def plot(self, df, plt):
        pass

    def getData(self, result):
        pass

    def start(self, conn, year, plt):
        conn1 = DataSource(ConfigClass.data['datasource1']).conn
        dzz=pd.read_sql('''select count(1) from v_dzzinfo''',con=conn1)
        dy=pd.read_sql('''select count(1) from  v_dysfzinfo
         where 政治面貌 like '%党员%'
        ''',con=conn1)
        self.fonts.append(Font(text=self.text.format(year,dzz.values[0][0],dy.values[0][0])))

if __name__ == '__main__':
    with open('D:\work\sanhuiyike\datareport\config.yaml', encoding='utf-8') as f:
        data = yaml.load(f, Loader=SafeLoader)
    con = DataSource(data['datasource']).conn
    BasicInformationContent_11().start(con, 2023, '')
